import { beforeAvatarUpload, videoupload } from "@/utils/method.js";

export default {
  data() {
    return {
      number: 2, // 
      upload2: false,
      static_list: [
        {
          file_url: '',
          type: 2,
          thumb_url: ''
        }, {
          file_url: '',
          type: 1,

        }, {
          file_url: '',
          type: 1,

        }, {
          file_url: '',
          type: 1,

        }, {
          file_url: '',
          type: 1,

        }, {
          file_url: '',
          type: 1,

        }
      ],
      route_service_details_list: [
        // 1 文字 2 图片 3 视频
        {
          type: 2,
          content: "",
          sort: 1,
          thumb_url: ""
        },
        {
          type: 3,
          url: '',
          content: "",
          sort: 2,
          thumb_url: ""
        },
        {
          type: 1,
          content: "",
          sort: 3,
          thumb_url: ""
        }
      ]
    }
  },
  beforeCreate() {
  },
  methods: {
    addimg() {
      this.route_service_details_list.push({
        type: 2, // 1 文字 2 图片 3 视频
        content: "",
        sort: 1, // 排序
        thumb_url: "" // 缩略图
      })
      // this.$set(this.imgcontent[number], img, 'hahah') // 设置动态img响应图
      // console.log(this.route_service_details_list);

    }, addmp4() {
      this.route_service_details_list.push({
        type: 3, // 1 文字 2 图片 3 视频
        content: "",
        sort: 1, // 排序
        thumb_url: "" // 缩略图
      })
      console.log("视频");
    }, addtextarea() {
      this.route_service_details_list.push({
        type: 1, // 1 文字 2 图片 3 视频
        content: "",
        sort: 1, // 排序
        thumb_url: "" // 缩略图
      })
      console.log("文案");
    },

    // 上传视频第一版
    changevideo1(e, num) {
      let _this = this
      var videourl = e.target.files[0];
      if (!videourl) return

      // 上传视频  视频太大传不了
      videoupload(videourl, _this).then((res) => {
        this.$refs.video.src = res;
        this.static_list[num].file_url = res // 返回的视频放路径上
        this.static_list[num].thumb_url = res + '?x-oss-process=video/snapshot,t_10000,m_fast'
      })
        .catch((error) => {
          console.log(error);
          this.$message.error('上传格式不正确哦🙁')
        });

      // 解决input同一视频只能上一次，下一次不触发事件
      e.target.value = null
      // var url = URL.createObjectURL(videourl);
      // this.$refs.video.src = url;
    },
    // 视频的上传处理
    changevideo(e, index) {
      let _this = this
      var videourl = e.target.files[0];
      videoupload(videourl, _this).then((res) => {

        this.route_service_details_list[index].content = res
        this.route_service_details_list[index].url = 'http' + res.split('https')[1]
        this.route_service_details_list[index].type = 3
        this.route_service_details_list[index].thumb_url = res + '?x-oss-process=video/snapshot,t_10000,m_fast'
      })
        .catch((error) => {
          console.log(error);
          this.$message.error('请上传正确的格式哦🙁')
        });
      e.target.value = null
    },
    // 文件上传处理
    upload1($event, num) {
      let _this = this

      beforeAvatarUpload($event, _this).then((res) => {
        this.static_list[num].file_url = res[0]
        this.static_list[num].type = 1
        this.static_list[num].thumb_url = ""
      })
      $event.target.value = null
    },
    // 详情列表图片上传处理
    upload($event, num) {
      let _this = this

      beforeAvatarUpload($event, _this).then((res) => {
        this.route_service_details_list[num].content = res[0]
        this.route_service_details_list[num].type = 2
        this.route_service_details_list[num].thumb_url = ""
      })
      $event.target.value = null
    },
    // 图片视频列表删除
    removeupload(num) {
      this.static_list[num].file_url = ''
      this.static_list[num].type = null
      this.static_list[num].thumb_url = ""
      this.$refs.video.src = "";
    },
    // 详情图片视频列表删除
    detailsremove(index) {
      this.route_service_details_list.splice(index, 1)
      console.log(this.route_service_details_list);
    },

  },
}